package com.nuoniu.sibanyun.controller.erp.in;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.dto.VInventoryCheckMainSearchDto;
import com.nuoniu.sibanyun.entity.erp.in.VInventoryCheckMain;
import com.nuoniu.sibanyun.service.erp.in.IVInventoryCheckMainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.nuoniu.sibanyun.common.BaseController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2021-05-19
 */
@RestController
@RequestMapping("/in/inventoryCheck")
@Api(value = "盘点", tags = "盘点")
public class VInventoryCheckMainController extends BaseController {

    @Autowired
    private IVInventoryCheckMainService ivInventoryCheckMainService;


    @ApiOperation("获取单据编码")
    @GetMapping("getCode")
    public HttpResult getCode() {
        return HttpResult.ok(ivInventoryCheckMainService.getCode());
    }

    @ApiOperation("保存")
    @PostMapping("save")
    public HttpResult save(@RequestBody VInventoryCheckMain vInventoryCheckMain) {
        ivInventoryCheckMainService.saveOrder(vInventoryCheckMain);
        return HttpResult.ok();
    }


    @ApiOperation("获取 盘点业务数据 （1:上一页、2:下一页、3:首页 和 4:尾页）")
    @GetMapping("getOneByCondition")
    public HttpResult<VInventoryCheckMain> getOneByCondition(Integer actionType, Long currentId,boolean isLossOrGain) {
        return HttpResult.ok(ivInventoryCheckMainService.getOneByCondition(actionType, currentId, isLossOrGain));
    }

    @ApiOperation("分页查询 盘点业务")
    @GetMapping("pageVInventoryCheckMain")
    public HttpResult<VInventoryCheckMain> pageVInventoryCheckMain(Page page, VInventoryCheckMainSearchDto inventoryCheckMainSearchDto) {
        return HttpResult.ok(ivInventoryCheckMainService.pageVInventoryCheckMain(page, inventoryCheckMainSearchDto));
    }


    /**
     * 复核
     * @date 2020-11-25
     */
    @GetMapping("firstExamine")
    @ApiOperation("复核")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "单据id"),
            @ApiImplicitParam(name = "status", value = "状态 0:取消复核,1:复核")
    })
    public HttpResult firstExamine(Long id, Integer status) {
        ivInventoryCheckMainService.firstExamine(id,status);
        return HttpResult.ok();
    }

    /**
     * 监盘
     * @date 2020-11-25
     */
    @GetMapping("secondExamine")
    @ApiOperation("监盘")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "单据id"),
            @ApiImplicitParam(name = "status", value = "状态 1:取消监盘,2:监盘")
    })
    public HttpResult secondExamine(Long id, Integer status) {
        ivInventoryCheckMainService.secondExamine(id,status);
        return HttpResult.ok();
    }

    /**
     * 批准
     * @date 2020-11-25
     */
    @GetMapping("thirdExamine")
    @ApiOperation("批准")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "单据id"),
            @ApiImplicitParam(name = "status", value = "状态 3 批准")
    })
    public HttpResult thirdExamine(Long id, Integer status) {
        ivInventoryCheckMainService.thirdExamine(id,status);
        return HttpResult.ok();
    }


    @ApiOperation("删除单据")
    @DeleteMapping("delete")
    public HttpResult delete(Long id) {
        ivInventoryCheckMainService.delete(id);
        return HttpResult.ok();
    }

}
